package com.premjit.logger;

public class Logger {
	//instance initiated, a singleton class??
	private static boolean loggerInitiated = false;
	//log levels
	private static boolean levelError = false;
	private static boolean levelWarn = false;
	private static boolean levelInfo = false;
	private static boolean levelDebug = false;
	
	public Logger(String level){
		if(!loggerInitiated){
			loggerInitiated = true;
			levelError = "error".equalsIgnoreCase(level)
							|| "warn".equalsIgnoreCase(level)
							|| "info".equalsIgnoreCase(level)
							|| "debug".equalsIgnoreCase(level);
			levelWarn = "warn".equalsIgnoreCase(level)
							|| "info".equalsIgnoreCase(level)
							|| "debug".equalsIgnoreCase(level);
			levelInfo = "info".equalsIgnoreCase(level)
							|| "debug".equalsIgnoreCase(level);
			levelDebug = "debug".equalsIgnoreCase(level);
		}
	}
	
	public static void error(String log){
		if(levelError){
			System.out.println("ERROR: "+log);
		}
	}
	
	public static void warn(String log){
		if(levelWarn){
			System.out.println("WARN: "+log);
		}
	}
	
	public static void info(String log){
		if(levelInfo){
			System.out.println("INFO: "+log);
		}
	}
	
	public static void debug(String log){
		if(levelDebug){
			System.out.println("DEBUG: "+log);
		}
	}
	
	public static String getLevel(){
		String str = //"" + 
			(levelDebug ? "DEBUG" : 
			(levelInfo ? "INFO" : 
			(levelWarn ? "WARN" : 
			(levelError ? "ERROR" : "NONE"))));
		return str;
	}

}
